package chapter14.Map.Exercise;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @Auther: Tx
 * @Date: 2022/5/19 17:35
 */
@SuppressWarnings("all")
public class Ex01 {
    public static void main(String[] args) {
        Map hashMap = new HashMap();
        hashMap.put("1", new Employee("mary", 15000, 1));
        hashMap.put("2", new Employee("lisa", 25000, 2));
        hashMap.put("3", new Employee("smith", 35000, 3));
//        第一种方式：增强for循环==>keySet
        Set keyset = hashMap.keySet();
        for (Object key : keyset) {
//        先获取value,通过key
            Employee employee = (Employee) hashMap.get(key);
            if (employee.getSal() > 18000) {
                System.out.println(employee);
            }
        }
        System.out.println("=================");
//        第二种方式：通过Entryset ==》迭代器
        Set entrySet = hashMap.entrySet();
        Iterator iterator = entrySet.iterator();
        while (iterator.hasNext()) {
         Map.Entry entry = (Map.Entry)iterator.next();
             Employee employee = (Employee) entry.getValue();
             if (employee.getSal()>18000){
                 System.out.println(employee);
             }
        }


    }
}

class Employee {
    private String name;
    private double sal;
    private int id;

    public int getId() {
        return id;
    }

    public Employee(String name, double sal, int id) {
        this.name = name;
        this.sal = sal;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", id=" + id +
                '}';
    }
}